<template>
  <div class="">
		<Form :model="FreezingDetail" label-position="left" :label-width="60">
	        
	        <Radio-group v-model="FreezingDetail.FreezingType" >
			    <Radio label="精子冷冻" :disabled="disabled">
			        <span>精子冷冻</span>
			    </Radio>
			    <Radio label="卵子冷冻" :disabled="disabled">
			        <span>卵子冷冻</span>
			    </Radio>
			    <Radio label="胚胎冷冻" :disabled="disabled">
			        <span>胚胎冷冻</span>
			    </Radio>
			</Radio-group>
			<div style="padding-top:10px" v-if="visible.精子冷冻">
				<Row>
					<Col span="20">

            <Form-item label="冷冻时间">
               
                    <Date-picker type="date" placeholder="选择日期" v-model="FreezingDetail.contentList[0]"></Date-picker>
                
            </Form-item>

						<Form-item label="精液数量"><Input v-model="FreezingDetail.contentList[1]"></Input></Form-item>
						<Form-item label="精子密度"><Input v-model="FreezingDetail.contentList[2]"></Input></Form-item>
						<Form-item label="存储期限"><Input v-model="FreezingDetail.contentList[3]"></Input></Form-item>
						
					</Col>
				</Row>
			</div>
			<div style="padding-top:10px" v-if="visible.卵子冷冻">
				<Row>
					<Col span="20">
             <Form-item label="冷冻时间">
       
                  <Date-picker type="date" placeholder="选择日期" v-model="FreezingDetail.contentList[0]"></Date-picker>
     
            </Form-item>
						<Form-item label="卵子数量"><Input v-model="FreezingDetail.contentList[1]"></Input></Form-item>
						<Form-item label="存储期限"><Input v-model="FreezingDetail.contentList[2]"></Input></Form-item>
						
						
					</Col>
				</Row>
			</div>
			<div style="padding-top:10px" v-if="visible.胚胎冷冻">
				<Row>
					<Col span="20">
            <Form-item label="冷冻时间">
              
                  <Date-picker type="date" placeholder="选择日期" v-model="FreezingDetail.contentList[0]"></Date-picker>
         
            </Form-item>
						<Form-item label="胚胎数量"><Input v-model="FreezingDetail.contentList[1]"></Input></Form-item>
						<Form-item label="胚胎等级"><Input v-model="FreezingDetail.contentList[2]"></Input></Form-item>
						<Form-item label="胚胎性别"><Input v-model="FreezingDetail.contentList[3]"></Input></Form-item>
						<Form-item label="存储期限"><Input v-model="FreezingDetail.contentList[4]"></Input></Form-item>
						
					</Col>
				</Row>
			</div>
			<div v-if="visible.uploadView">
				<upload-helper 
        type="ovl"
        @handleSuccess="handleSuccess"
         v-bind:defaultList="FreezingDetail.rusultlist"  
         LeftTitle="上传报告" 
         v-bind:selectType="bodyType">
      </upload-helper>
			</div>
        </Form>
        
  </div>
</template>
<script>
import UploadHelper from '../components/UploadHelper'
import api from '../js/axios-module'
export default {

  data () {
    return {
    	bodyType:'',
    	disabled:false,
        visible:{
        	"精子冷冻":false,
        	"卵子冷冻":false,
        	"胚胎冷冻":false,
        	"uploadView":false,
        },
    	FreezingDetail:{
        id:"",
    		FreezingType: '精子冷冻',
    		date:'',
        contentList:[],
        rusultlist:[],
    		
    	},
    	
      
       
    }
  },
  components:{UploadHelper},
  methods:{
    handleSuccess:function(res,flie,selectType,type){

        this.FreezingDetail.rusultlist.push({
            url : flie.url,
            name : flie.url
        })

    },
  	openItem:function(number){
  		
  		if (number !=-1) {
  			//get
  			this.FreezingDetail.FreezingType= this.FreezingStorage.data[number].type  
  			this.FreezingDetail.contentList =this.FreezingStorage.data[number].contentList
        this.FreezingDetail.rusultlist  = this.FreezingStorage.data[number].rusultlist 
        this.FreezingDetail.id = this.FreezingStorage.data[number].id 
        this.FreezingDetail.date = this.FreezingStorage.data[number].date
        // console.log(this.FreezingDetail)

  		}else{
        //新增
        this.disabled = false
  			this.FreezingDetail.FreezingType = ""
        this.FreezingDetail.rusultlist = []
        this.FreezingDetail.contentList = []
  			for (var prop in this.visible) { 
  				  this.visible.prop=false;
  			
			   }

  		}


  		
  	},getParams:function(){
       var params = new Object();
       var data = new Object();

          data.date = this.FreezingDetail.contentList[0];
          if(this.FreezingDetail.contentList[0]==undefined){
            var date = new Date()
            this.FreezingDetail.contentList[0] = date.format("yyyy-MM-dd")
          }
       if (this.FreezingDetail.FreezingType =='精子冷冻') {

            data.spermnumber = this.FreezingDetail.contentList[1]
            data.spermdensity= this.FreezingDetail.contentList[2]
            data.time= this.FreezingDetail.contentList[3]

          }else if(this.FreezingDetail.FreezingType == '卵子冷冻'){
            data.eggnumber = this.FreezingDetail.contentList[1] 
            data.time =  this.FreezingDetail.contentList[2] 

          }else if(this.FreezingDetail.FreezingType == '胚胎冷冻'){
            data.embryonumber = this.FreezingDetail.contentList[1] 
            data.embryograde = this.FreezingDetail.contentList[2] 
            data.embryosex = this.FreezingDetail.contentList[3] 
            data.time = this.FreezingDetail.contentList[4] 
          }

          params.frozenid = this.FreezingDetail.id
          params.type = this.FreezingDetail.FreezingType;
          params.data = data;
          params.file =  this.FreezingDetail.rusultlist;
          return params;

    },
  	updateItem:function(number){


  		
  		if (number !=-1) {

          api.editFreezingStorage(this.getParams()).then(response=>{
              console.log(response)
              this.FreezingStorage.data[number].type = this.FreezingDetail.FreezingType ;
              this.FreezingStorage.data[number].contentList = this.FreezingDetail.contentList ;
              this.FreezingStorage.data[number].rusultlist = this.FreezingDetail.rusultlist ;


          },err=>{

            this.$Message.error("提交失败,请稍后再试")
          })

  		}else{
  			//add

          api.setFreezingStorage(this.getParams()).then(response=>{

            console.log(response.data.id)

            this.FreezingStorage.data.push({
                "id":response.data.id,
                "type":this.FreezingDetail.FreezingType,
                "contentList":this.FreezingDetail.contentList,
                "rusultlist":this.FreezingDetail.rusultlist
              });

          },err=>{
            this.$Message.error("提交失败,请稍后再试")
          })



  		}
  	}

  },props:['FreezingStorage'],
  watch:{
  	'FreezingDetail':{
  		handler:function(val,oldval){
        
    			for (var prop in this.visible) { 	
            //隐藏和展示对应的表格
    				this.visible[prop]=false;
    				if (prop == this.FreezingDetail.FreezingType) {
    					this.visible[prop] = true;
    					this.bodyType = val;
               this.disabled = true
    				}
  			 }
          
          this.visible.uploadView = true
			   
  		},
  		deep:true
  	}
  }
}
</script>
<style scoped>   


</style>